#pragma once
#include <vector>
#include <string>
using namespace std;

/// @brief 城市结构体
struct city {
    double posX;
    double posY;
    string name;
    city(double posX, double posY, string name);
};

/// @brief 路线结构体
struct route {
    vector<city> cities;
    /// @brief 构造一条路线
    route(vector<city> cities);
    /// @brief 随机化当前的路线
    void randomize();
    /// @brief 交换指定下标两个城市的位置
    void swap(int swapIndex1, int swapIndex2);
    /// @brief 返回本条路线长度
    /// @return 长度定义为从i = 0到cities.size() - 1，
    /// @return 对于每对(cities[i] % size, cities[i + 1] % size)的几何距离的累加。
    double returnRouteLength();
    /// @brief 返回一条路线的适应度
    /// @return 对距离为dist的路线，返回其适应度为exp(-0.01 * dist)
    double getAdaptability(const double ratio);
};

/// @brief 结果结构体
struct result {
    /// @brief 路线情况
    vector<city> cities;
    /// @brief 距离
    double distance;
    result();
    string returnAsFinalOutput();
    string returnResultOutput(int round);
};

void tryMutation(route& currRoute, const double percentage);
void doCrossOver(route& route1, route& route2);

double returnDistance(const city& city1, const city& city2);
vector<route> initalize(const vector<city>& cities, const int routeCnt);
result returnCurrSolution(vector<route>& routes);
int chooseRoute(vector<route>& routes);
result returnPossibleSolution(vector<city>& cities, const int activeLimit, const int freezeLimit);